package com.thrsdk.ui.dialog;


import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.thrsdk.constants.AppConfig;
import com.thrsdk.listener.IListener;
import com.thrsdk.model.protocol.bean.LoginMessage;
import com.thrsdk.utils.GameCofig;

public class LoginDialog extends Dialog {
    private Context mContext;
    private View mView;
    private IListener<LoginMessage> mListener;
    private Button mLogin;
    private EditText edt_loginname;
    private TextView tv_fusion_url;

    public LoginDialog(Context context, IListener<LoginMessage> listener) {
        super(context, AppConfig.resourceId(context,
                "thf_MyDialog", "style"));
        // TODO Auto-generated constructor stub
        this.mContext = context;
        this.mListener = listener;
        this.mView = LayoutInflater.from(context).inflate(
                AppConfig.resourceId(context, "thf_login_dialog", "layout"),
                null);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(mView);
        edt_loginname = (EditText) findViewById(AppConfig.resourceId(mContext, "edt_loginname", "id"));

        String str_num = (int) (Math.random() * 10000) + "";
        edt_loginname.setText(str_num);
        edt_loginname.setSelection(str_num.length());
        mLogin = (Button) findViewById(AppConfig.resourceId(mContext, "dialog_login", "id"));
        mLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (null != mLoginInterface) {
                    String str_loginname = edt_loginname.getText().toString().trim();
                    mLoginInterface.clickLogin(str_loginname);
                }
            }
        });
        this.setCancelable(false);
        this.setCanceledOnTouchOutside(false);

        tv_fusion_url = (TextView) findViewById(AppConfig.resourceId(mContext, "tv_fusion_url", "id"));
        String url = GameCofig.getUrl(mContext);
        if (!TextUtils.isEmpty(url)) {
            tv_fusion_url.setText("请求域名：" + url);
        }
    }

    public LoginInterface mLoginInterface;

    public interface LoginInterface {
        void clickLogin(String str_loginname);
    }

    public void setmLoginInterface(LoginInterface mLoginInterface) {
        this.mLoginInterface = mLoginInterface;
    }
}
